package com.glsc.ngateway.opmanage.controller.performance;

import com.glsc.ngateway.common.api.common.utils.PageUtil;
import com.glsc.ngateway.common.api.platform.resp.PlatformResponse;
import com.glsc.ngateway.common.base.domain.mysql.gateway.platform.User;
import com.glsc.ngateway.common.base.domain.mysql.opmanagemain.performance.DayPerformance;
import com.glsc.ngateway.opmanage.aspect.UserCache;
import com.glsc.ngateway.opmanage.dto.*;
import com.glsc.ngateway.opmanage.service.performance.DayPerformanceItemService;
import com.glsc.ngateway.opmanage.service.performance.DayPerformanceService;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.compress.utils.Lists;
import org.apache.commons.lang.StringUtils;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 绩效管理- 每日总积分表
 */
@RestController
@RequestMapping("/api/performance")
@Slf4j
public class DayPerformanceController {

    @Resource
    private UserCache userCache;

    @Resource
    private DayPerformanceService dayPerformanceService;

    @Resource
    private DayPerformanceItemService dayPerformanceItemService;


    /**
     * 分页查询
     *
     * @param obj
     * @return
     */
    @PostMapping("/page")
    public PlatformResponse<Page<DayPerformance>> page(@RequestBody DayPerformanceDto obj) {

        Map<String, Object> param = new HashMap<>();

        if (StringUtils.isNotBlank(obj.getUserName())) {
            param.put("LIKE_userName", obj.getUserName());
        }
        if (StringUtils.isNotBlank(obj.getPostName())) {
            param.put("LIKE_postName", obj.getPostName());
        }

        Page<DayPerformance> page = dayPerformanceService.page(PageUtil.initPageNo(obj.getPageNo()), PageUtil.initPageSize(obj.getPageSize()), param);
        return PlatformResponse.successData(page);
    }


    @PostMapping("/performanceYsp")
    public PlatformResponse<List<PerformanceGuYanDto>> performanceYsp(@RequestBody DayPerformanceDto obj) {

//        perfMap.put("孙伟平", LedgerPerfDtoItem.builder().userName("孙伟平").postName("股衍运营岗").swapHour(0).customerHour(0).foundationHour(0).incomeHour(0).manHour(0).settlementHour(0).manHour(0).build());
//        perfMap.put("陶轶铭", LedgerPerfDtoItem.builder().userName("陶轶铭").postName("股衍运营岗").swapHour(0).customerHour(0).foundationHour(0).incomeHour(0).manHour(0).settlementHour(0).manHour(0).build());
//        perfMap.put("赵正彦", LedgerPerfDtoItem.builder().userName("赵正彦").postName("股衍运营岗").swapHour(0).customerHour(0).foundationHour(0).incomeHour(0).manHour(0).settlementHour(0).manHour(0).build());
//        perfMap.put("毕翠翠", LedgerPerfDtoItem.builder().userName("毕翠翠").postName("股衍运营岗").swapHour(0).customerHour(0).foundationHour(0).incomeHour(0).manHour(0).settlementHour(0).manHour(0).build());

        List<PerformanceGuYanDto> resultList = Lists.newArrayList();
        PerformanceGuYanDto sunwpDto = PerformanceGuYanDto.builder().userName("孙伟平").postName("股衍运营岗").build();
        PerformanceGuYanDto taoymDto = PerformanceGuYanDto.builder().userName("陶轶铭").postName("股衍运营岗").build();
        PerformanceGuYanDto zzyDto = PerformanceGuYanDto.builder().userName("赵正彦").postName("股衍运营岗").build();
        PerformanceGuYanDto biccDto = PerformanceGuYanDto.builder().userName("毕翠翠").postName("股衍运营岗").build();

        resultList.add(sunwpDto);
        resultList.add(taoymDto);
        resultList.add(zzyDto);
        resultList.add(biccDto);

        LocalDateTime startTime = obj.getStartTime().atTime(LocalTime.MIDNIGHT);
        LocalDateTime endTime = obj.getEndTime().atTime(LocalTime.MAX);

        Integer sunwp = dayPerformanceService.findUserSumManHourByPostName("sunwp", "股衍运营岗", startTime, endTime);
        sunwpDto.setManHour(sunwp);
        sunwpDto.setIncomeHour(dayPerformanceItemService.findUserSumManHour("sunwp", startTime, endTime, "shouyi_pingzheng", "股衍运营岗"));
        sunwpDto.setCustomerHour(dayPerformanceItemService.findUserSumManHour("sunwp", startTime, endTime, "kyc_org", "股衍运营岗"));
        sunwpDto.setSwapHour(dayPerformanceItemService.findUserSumManHour("sunwp", startTime, endTime, "jiaoyi_yewu", "股衍运营岗"));
        sunwpDto.setFoundationHour(dayPerformanceItemService.findUserSumManHour("sunwp", startTime, endTime, "jijin_shenshu", "股衍运营岗"));
        sunwpDto.setSettlementHour(dayPerformanceItemService.findUserSumManHour("sunwp", startTime, endTime, "qing_suan", "股衍运营岗"));


        Integer taoym = dayPerformanceService.findUserSumManHourByPostName("taoym", "股衍运营岗", startTime, endTime);
        taoymDto.setManHour(taoym);
        taoymDto.setIncomeHour(dayPerformanceItemService.findUserSumManHour("taoym", startTime, endTime, "shouyi_pingzheng", "股衍运营岗"));
        taoymDto.setCustomerHour(dayPerformanceItemService.findUserSumManHour("taoym", startTime, endTime, "kyc_org", "股衍运营岗"));
        taoymDto.setSwapHour(dayPerformanceItemService.findUserSumManHour("taoym", startTime, endTime, "jiaoyi_yewu", "股衍运营岗"));
        taoymDto.setFoundationHour(dayPerformanceItemService.findUserSumManHour("taoym", startTime, endTime, "jijin_shenshu", "股衍运营岗"));
        taoymDto.setSettlementHour(dayPerformanceItemService.findUserSumManHour("taoym", startTime, endTime, "qing_suan", "股衍运营岗"));

        Integer zzy = dayPerformanceService.findUserSumManHourByPostName("zzy", "股衍运营岗", startTime, endTime);
        zzyDto.setManHour(zzy);
        zzyDto.setIncomeHour(dayPerformanceItemService.findUserSumManHour("zzy", startTime, endTime, "shouyi_pingzheng", "股衍运营岗"));
        zzyDto.setCustomerHour(dayPerformanceItemService.findUserSumManHour("zzy", startTime, endTime, "kyc_org", "股衍运营岗"));
        zzyDto.setSwapHour(dayPerformanceItemService.findUserSumManHour("zzy", startTime, endTime, "jiaoyi_yewu", "股衍运营岗"));
        zzyDto.setFoundationHour(dayPerformanceItemService.findUserSumManHour("zzy", startTime, endTime, "jijin_shenshu", "股衍运营岗"));
        zzyDto.setSettlementHour(dayPerformanceItemService.findUserSumManHour("zzy", startTime, endTime, "qing_suan", "股衍运营岗"));


        Integer bicc = dayPerformanceService.findUserSumManHourByPostName("bicc", "股衍运营岗", startTime, endTime);
        biccDto.setManHour(bicc);
        biccDto.setIncomeHour(dayPerformanceItemService.findUserSumManHour("bicc", startTime, endTime, "shouyi_pingzheng", "股衍运营岗"));
        biccDto.setCustomerHour(dayPerformanceItemService.findUserSumManHour("bicc", startTime, endTime, "kyc_org", "股衍运营岗"));
        biccDto.setSwapHour(dayPerformanceItemService.findUserSumManHour("bicc", startTime, endTime, "jiaoyi_yewu", "股衍运营岗"));
        biccDto.setFoundationHour(dayPerformanceItemService.findUserSumManHour("bicc", startTime, endTime, "jijin_shenshu", "股衍运营岗"));
        biccDto.setSettlementHour(dayPerformanceItemService.findUserSumManHour("bicc", startTime, endTime, "qing_suan", "股衍运营岗"));

        resultList.forEach(e -> {
            if (Objects.isNull(e.getManHour())) {
                e.setManHour(0);
            }
        });
        resultList = resultList.stream().sorted(Comparator.comparing(PerformanceGuYanDto::getManHour).reversed()).collect(Collectors.toList());

        return PlatformResponse.successData(resultList);
    }


    @PostMapping("/performanceZongHe")
    public PlatformResponse<List<PerformanceZongHeDto>> performanceZongHe(@RequestBody DayPerformanceDto obj) {

//        perfMap.put("肖丹", LedgerZongHeDtoItem.builder().userName("肖丹").postName("综合运营岗").dangWuHour(0).zongHeHour(0).renLiHour(0).xiTongHour(0).ziYouZiJinHour(0).jiaoYiDanYuanHour(0).qiTaHour(0).manHour(0).build());
//        perfMap.put("周洁", LedgerZongHeDtoItem.builder().userName("周洁").postName("综合运营岗").dangWuHour(0).zongHeHour(0).renLiHour(0).xiTongHour(0).ziYouZiJinHour(0).jiaoYiDanYuanHour(0).qiTaHour(0).manHour(0).build());

        List<PerformanceZongHeDto> resultList = Lists.newArrayList();
        PerformanceZongHeDto xiaodDto = PerformanceZongHeDto.builder().postName("综合运营岗").userName("肖丹").build();
        PerformanceZongHeDto zhoujieDto = PerformanceZongHeDto.builder().postName("综合运营岗").userName("周洁").build();

        resultList.add(xiaodDto);
        resultList.add(zhoujieDto);

        LocalDateTime startTime = obj.getStartTime().atTime(LocalTime.MIDNIGHT);
        LocalDateTime endTime = obj.getEndTime().atTime(LocalTime.MAX);

        Integer fanyy = dayPerformanceService.findUserSumManHourByPostName("xiaod", "综合运营岗", startTime, endTime);
        xiaodDto.setManHour(fanyy);
        xiaodDto.setDangWuHour(dayPerformanceItemService.findUserSumManHour("xiaod", startTime, endTime, "dangwu", "综合运营岗"));
        xiaodDto.setZongHeHour(dayPerformanceItemService.findUserSumManHour("xiaod", startTime, endTime, "zonghe_shiwu", "综合运营岗"));
        xiaodDto.setRenLiHour(dayPerformanceItemService.findUserSumManHour("xiaod", startTime, endTime, "renli_shixiang", "综合运营岗"));
        xiaodDto.setXiTongHour(dayPerformanceItemService.findUserSumManHour("xiaod", startTime, endTime, "xitong_quanxian_gl", "综合运营岗"));
        xiaodDto.setZiYouZiJinHour(dayPerformanceItemService.findUserSumManHour("xiaod", startTime, endTime, "zhanghu_guanli", "综合运营岗"));
        xiaodDto.setJiaoYiDanYuanHour(dayPerformanceItemService.findUserSumManHour("xiaod", startTime, endTime, "jiaoyi_danyuan_gl", "综合运营岗"));
        xiaodDto.setQiTaHour(dayPerformanceItemService.findUserSumManHour("xiaod", startTime, endTime, "jrscqt", "综合运营岗"));


        Integer ant = dayPerformanceService.findUserSumManHourByPostName("zhoujie", "综合运营岗", startTime, endTime);
        zhoujieDto.setManHour(ant);
        zhoujieDto.setDangWuHour(dayPerformanceItemService.findUserSumManHour("zhoujie", startTime, endTime, "dangwu", "综合运营岗"));
        zhoujieDto.setZongHeHour(dayPerformanceItemService.findUserSumManHour("zhoujie", startTime, endTime, "zonghe_shiwu", "综合运营岗"));
        zhoujieDto.setRenLiHour(dayPerformanceItemService.findUserSumManHour("zhoujie", startTime, endTime, "renli_shixiang", "综合运营岗"));
        zhoujieDto.setXiTongHour(dayPerformanceItemService.findUserSumManHour("zhoujie", startTime, endTime, "xitong_quanxian_gl", "综合运营岗"));
        zhoujieDto.setZiYouZiJinHour(dayPerformanceItemService.findUserSumManHour("zhoujie", startTime, endTime, "zhanghu_guanli", "综合运营岗"));
        zhoujieDto.setJiaoYiDanYuanHour(dayPerformanceItemService.findUserSumManHour("zhoujie", startTime, endTime, "jiaoyi_danyuan_gl", "综合运营岗"));
        zhoujieDto.setQiTaHour(dayPerformanceItemService.findUserSumManHour("zhoujie", startTime, endTime, "jrscqt", "综合运营岗"));

        resultList.forEach(e -> {
            if (Objects.isNull(e.getManHour())) {
                e.setManHour(0);
            }
        });
        resultList = resultList.stream().sorted(Comparator.comparing(PerformanceZongHeDto::getManHour).reversed()).collect(Collectors.toList());


        return PlatformResponse.successData(resultList);
    }


    /**
     * 交易岗绩效查询
     *
     * @param obj
     * @return
     */
    @PostMapping("/performanceJiaoYi")
    public PlatformResponse<List<PerformanceJiaoYiDto>> performanceJiaoYi(@RequestBody DayPerformanceDto obj) {

//        perfMap.put("范漪漪", LedgerJiaoYiDtoItem.builder().userName("范漪漪").postName("综合运营岗").daZongHour(0).ziYouGuZhiHour(0).jiJinHour(0).manHour(0).build());
//        perfMap.put("安恬", LedgerJiaoYiDtoItem.builder().userName("安恬").postName("综合运营岗").daZongHour(0).ziYouGuZhiHour(0).jiJinHour(0).manHour(0).build());
//        perfMap.put("陈诗佳", LedgerJiaoYiDtoItem.builder().userName("陈诗佳").postName("综合运营岗").daZongHour(0).ziYouGuZhiHour(0).jiJinHour(0).manHour(0).build());

        List<PerformanceJiaoYiDto> resultList = Lists.newArrayList();
        PerformanceJiaoYiDto fanyyDto = PerformanceJiaoYiDto.builder().userName("范漪漪").postName("交易岗").build();
        PerformanceJiaoYiDto antDto = PerformanceJiaoYiDto.builder().userName("安恬").postName("交易岗").build();
        PerformanceJiaoYiDto chenshjDto = PerformanceJiaoYiDto.builder().userName("陈诗佳").postName("交易岗").build();

        resultList.add(fanyyDto);
        resultList.add(antDto);
        resultList.add(chenshjDto);

        LocalDateTime startTime = obj.getStartTime().atTime(LocalTime.MIDNIGHT);
        LocalDateTime endTime = obj.getEndTime().atTime(LocalTime.MAX);

        Integer fanyy = dayPerformanceService.findUserSumManHourByPostName("fanyy", "交易岗", startTime, endTime);
        fanyyDto.setManHour(fanyy);
        fanyyDto.setDaZongHour(dayPerformanceItemService.findUserSumManHour("fanyy", startTime, endTime, "dazong_jiaoyi", "交易岗"));
        fanyyDto.setZiYouGuZhiHour(dayPerformanceItemService.findUserSumManHour("fanyy", startTime, endTime, "guzhi_xingquan", "交易岗"));
        fanyyDto.setJiJinHour(dayPerformanceItemService.findUserSumManHour("fanyy", startTime, endTime, "jijin_tougu", "交易岗"));


        Integer ant = dayPerformanceService.findUserSumManHourByPostName("ant", "交易岗", startTime, endTime);
        antDto.setManHour(ant);
        antDto.setDaZongHour(dayPerformanceItemService.findUserSumManHour("ant", startTime, endTime, "dazong_jiaoyi", "交易岗"));
        antDto.setZiYouGuZhiHour(dayPerformanceItemService.findUserSumManHour("ant", startTime, endTime, "guzhi_xingquan", "交易岗"));
        antDto.setJiJinHour(dayPerformanceItemService.findUserSumManHour("ant", startTime, endTime, "jijin_tougu", "交易岗"));


        Integer chenshj = dayPerformanceService.findUserSumManHourByPostName("chenshj", "交易岗", startTime, endTime);
        chenshjDto.setManHour(chenshj);
        chenshjDto.setDaZongHour(dayPerformanceItemService.findUserSumManHour("chenshj", startTime, endTime, "dazong_jiaoyi", "交易岗"));
        chenshjDto.setZiYouGuZhiHour(dayPerformanceItemService.findUserSumManHour("chenshj", startTime, endTime, "guzhi_xingquan", "交易岗"));
        chenshjDto.setJiJinHour(dayPerformanceItemService.findUserSumManHour("chenshj", startTime, endTime, "jijin_tougu", "交易岗"));

        resultList.forEach(e -> {
            if (Objects.isNull(e.getManHour())) {
                e.setManHour(0);
            }
        });
        resultList = resultList.stream().sorted(Comparator.comparing(PerformanceJiaoYiDto::getManHour).reversed()).collect(Collectors.toList());

        return PlatformResponse.successData(resultList);
    }

    @PostMapping("/performanceGuShou")
    public PlatformResponse<List<PerformanceGuShouDto>> performanceGuShou(@RequestBody DayPerformanceDto obj) {
//        perfMap.put("安恬", LedgerGuShouDtoItem.builder().userName("安恬").postName("固收运营岗").baoBiaoHour(0).huHuanHour(0).jieSuanHour(0).ziJinHour(0).manHour(0).build());
//        perfMap.put("范漪漪", LedgerGuShouDtoItem.builder().userName("范漪漪").postName("固收运营岗").baoBiaoHour(0).huHuanHour(0).jieSuanHour(0).ziJinHour(0).manHour(0).build());
//        perfMap.put("何泉震", LedgerGuShouDtoItem.builder().userName("何泉震").postName("固收运营岗").baoBiaoHour(0).huHuanHour(0).jieSuanHour(0).ziJinHour(0).manHour(0).build());
//        perfMap.put("姚金岐", LedgerGuShouDtoItem.builder().userName("姚金岐").postName("固收运营岗").baoBiaoHour(0).huHuanHour(0).jieSuanHour(0).ziJinHour(0).manHour(0).build());

        List<PerformanceGuShouDto> resultList = Lists.newArrayList();
        PerformanceGuShouDto fanyyDto = PerformanceGuShouDto.builder().userName("范漪漪").postName("固收运营岗").build();
        PerformanceGuShouDto antDto = PerformanceGuShouDto.builder().userName("安恬").postName("固收运营岗").build();
        PerformanceGuShouDto heqzhDto = PerformanceGuShouDto.builder().userName("何泉震").postName("固收运营岗").build();
        PerformanceGuShouDto yaojqDto = PerformanceGuShouDto.builder().userName("姚金岐").postName("固收运营岗").build();

        resultList.add(fanyyDto);
        resultList.add(antDto);
        resultList.add(heqzhDto);
        resultList.add(yaojqDto);

        LocalDateTime startTime = obj.getStartTime().atTime(LocalTime.MIDNIGHT);
        LocalDateTime endTime = obj.getEndTime().atTime(LocalTime.MAX);

        Integer fanyy = dayPerformanceService.findUserSumManHourByPostName("fanyy", "固收运营岗", startTime, endTime);
        fanyyDto.setManHour(fanyy);
        fanyyDto.setBaoBiaoHour(dayPerformanceItemService.findUserSumManHour("fanyy", startTime, endTime, "gushou_yunying_bb", "固收运营岗"));
        fanyyDto.setHuHuanHour(dayPerformanceItemService.findUserSumManHour("fanyy", startTime, endTime, "gushou_yunying_hh", "固收运营岗"));
        fanyyDto.setJieSuanHour(dayPerformanceItemService.findUserSumManHour("fanyy", startTime, endTime, "gushou_yunying_js", "固收运营岗"));
        fanyyDto.setZiJinHour(dayPerformanceItemService.findUserSumManHour("fanyy", startTime, endTime, "gushou_yunying_zj", "固收运营岗"));


        Integer ant = dayPerformanceService.findUserSumManHourByPostName("ant", "固收运营岗", startTime, endTime);
        antDto.setManHour(ant);
        antDto.setBaoBiaoHour(dayPerformanceItemService.findUserSumManHour("ant", startTime, endTime, "gushou_yunying_bb", "固收运营岗"));
        antDto.setHuHuanHour(dayPerformanceItemService.findUserSumManHour("ant", startTime, endTime, "gushou_yunying_hh", "固收运营岗"));
        antDto.setJieSuanHour(dayPerformanceItemService.findUserSumManHour("ant", startTime, endTime, "gushou_yunying_js", "固收运营岗"));
        antDto.setZiJinHour(dayPerformanceItemService.findUserSumManHour("ant", startTime, endTime, "gushou_yunying_zj", "固收运营岗"));


        Integer heqzh = dayPerformanceService.findUserSumManHourByPostName("heqzh", "固收运营岗", startTime, endTime);
        heqzhDto.setManHour(heqzh);
        heqzhDto.setBaoBiaoHour(dayPerformanceItemService.findUserSumManHour("heqzh", startTime, endTime, "gushou_yunying_bb", "固收运营岗"));
        heqzhDto.setHuHuanHour(dayPerformanceItemService.findUserSumManHour("heqzh", startTime, endTime, "gushou_yunying_hh", "固收运营岗"));
        heqzhDto.setJieSuanHour(dayPerformanceItemService.findUserSumManHour("heqzh", startTime, endTime, "gushou_yunying_js", "固收运营岗"));
        heqzhDto.setZiJinHour(dayPerformanceItemService.findUserSumManHour("heqzh", startTime, endTime, "gushou_yunying_zj", "固收运营岗"));


        Integer yaojq = dayPerformanceService.findUserSumManHourByPostName("yaojq", "固收运营岗", startTime, endTime);
        yaojqDto.setManHour(yaojq);
        yaojqDto.setManHour(yaojq);
        yaojqDto.setBaoBiaoHour(dayPerformanceItemService.findUserSumManHour("yaojq", startTime, endTime, "gushou_yunying_bb", "固收运营岗"));
        yaojqDto.setHuHuanHour(dayPerformanceItemService.findUserSumManHour("yaojq", startTime, endTime, "gushou_yunying_hh", "固收运营岗"));
        yaojqDto.setJieSuanHour(dayPerformanceItemService.findUserSumManHour("yaojq", startTime, endTime, "gushou_yunying_js", "固收运营岗"));
        yaojqDto.setZiJinHour(dayPerformanceItemService.findUserSumManHour("yaojq", startTime, endTime, "gushou_yunying_zj", "固收运营岗"));

        resultList.forEach(e -> {
            if (Objects.isNull(e.getManHour())) {
                e.setManHour(0);
            }
        });
        resultList = resultList.stream().sorted(Comparator.comparing(PerformanceGuShouDto::getManHour).reversed()).collect(Collectors.toList());

        return PlatformResponse.successData(resultList);
    }


    /**
     * 清算岗-绩效管理
     *
     * @param obj
     * @return
     */
    @PostMapping("/performanceQingSuan")
    public PlatformResponse<List<PerformanceQingSuanDto>> performanceQingSuan(@RequestBody DayPerformanceDto obj) {

        Map<String, Object> param = new HashMap<>();
        param.put("LIKE_postName", "清算岗");
        if (StringUtils.isNotBlank(obj.getUserName())) {
            param.put("LIKE_userName", obj.getUserName());
        }

//        perfMap.put("杨珂", LedgerQingSuanDtoItem.builder().userName("杨珂").postName("清算岗").beiDongHour(0).zhuDongHour(0).manHour(0).build());
//        perfMap.put("徐苏", LedgerQingSuanDtoItem.builder().userName("徐苏").postName("清算岗").beiDongHour(0).zhuDongHour(0).manHour(0).build());
//        perfMap.put("刘涵煜", LedgerQingSuanDtoItem.builder().userName("刘涵煜").postName("清算岗").beiDongHour(0).zhuDongHour(0).manHour(0).build());
//        perfMap.put("许晟晖", LedgerQingSuanDtoItem.builder().userName("许晟晖").postName("清算岗").beiDongHour(0).zhuDongHour(0).manHour(0).build());
//        perfMap.put("徐浩昕", LedgerQingSuanDtoItem.builder().userName("徐浩昕").postName("清算岗").beiDongHour(0).zhuDongHour(0).manHour(0).build());


        List<PerformanceQingSuanDto> resultList = Lists.newArrayList();
        PerformanceQingSuanDto yangkeDto = PerformanceQingSuanDto.builder().postName("清算岗").userName("杨珂").passiveHour(0).build();
        PerformanceQingSuanDto xusDto = PerformanceQingSuanDto.builder().postName("清算岗").userName("徐苏").passiveHour(0).build();
        PerformanceQingSuanDto liuhyDto = PerformanceQingSuanDto.builder().postName("清算岗").userName("刘涵煜").passiveHour(0).build();
        PerformanceQingSuanDto xushDto = PerformanceQingSuanDto.builder().postName("清算岗").userName("许晟晖").passiveHour(0).build();
        PerformanceQingSuanDto xhxDto = PerformanceQingSuanDto.builder().postName("清算岗").userName("徐浩昕").passiveHour(0).build();

        resultList.add(yangkeDto);
        resultList.add(xusDto);
        resultList.add(liuhyDto);
        resultList.add(xushDto);
        resultList.add(xhxDto);

        LocalDateTime startTime = obj.getStartTime().atTime(LocalTime.MIDNIGHT);
        LocalDateTime endTime = obj.getEndTime().atTime(LocalTime.MAX);

        yangkeDto.setAccordHour(dayPerformanceService.findUserSumAccordHour("yangke", startTime, endTime));
        yangkeDto.setManHour(yangkeDto.getAccordHour());

        xusDto.setAccordHour(dayPerformanceService.findUserSumAccordHour("xus", startTime, endTime));
        xusDto.setManHour(xusDto.getAccordHour());

        liuhyDto.setAccordHour(dayPerformanceService.findUserSumAccordHour("liuhy", startTime, endTime));
        liuhyDto.setManHour(liuhyDto.getAccordHour());

        xushDto.setAccordHour(dayPerformanceService.findUserSumAccordHour("xush", startTime, endTime));
        xushDto.setManHour(xushDto.getAccordHour());

        xhxDto.setAccordHour(dayPerformanceService.findUserSumAccordHour("xhx", startTime, endTime));
        xhxDto.setManHour(xhxDto.getAccordHour());

        resultList.forEach(e -> {
            if (Objects.isNull(e.getManHour())) {
                e.setManHour(0);
            }
        });
        resultList = resultList.stream().sorted(Comparator.comparing(PerformanceQingSuanDto::getManHour).reversed()).collect(Collectors.toList());

        return PlatformResponse.successData(resultList);
    }


    /**
     * 根据di查询
     *
     * @param
     * @return
     */
    @GetMapping("/findById")
    public PlatformResponse<DayPerformance> findById(@ApiParam(value = "id") @RequestParam(required = true) Integer id) {
        return PlatformResponse.successData(dayPerformanceService.findById(id));
    }

    /**
     * 保存
     *
     * @param obj
     * @return
     */
    @PostMapping("/save")
    public PlatformResponse<DayPerformance> save(@RequestBody DayPerformance obj, HttpServletRequest request) {
        User user = userCache.get(request);
        obj.setUserName(user.getName());
        obj.setUserId(user.getId().intValue());
        obj.setUserOaAccount(user.getUsername());
        DayPerformance save = dayPerformanceService.save(obj);
        return PlatformResponse.successData(save);
    }

    /**
     * 金融市场支持组-全组绩效看板
     *
     * @param obj
     * @return
     */
    @PostMapping("/performanceFinAll")
    public PlatformResponse<List<PerformanceJiaoYiDto>> performanceFinAll(@RequestBody DayPerformanceDto obj) {

//        perfMap.put("孙伟平", LedgerPerfDtoItem.builder().userName("孙伟平").postName("股衍运营岗").swapHour(0).customerHour(0).foundationHour(0).incomeHour(0).manHour(0).settlementHour(0).manHour(0).build());
//        perfMap.put("陶轶铭", LedgerPerfDtoItem.builder().userName("陶轶铭").postName("股衍运营岗").swapHour(0).customerHour(0).foundationHour(0).incomeHour(0).manHour(0).settlementHour(0).manHour(0).build());
//        perfMap.put("赵正彦", LedgerPerfDtoItem.builder().userName("赵正彦").postName("股衍运营岗").swapHour(0).customerHour(0).foundationHour(0).incomeHour(0).manHour(0).settlementHour(0).manHour(0).build());
//        perfMap.put("毕翠翠", LedgerPerfDtoItem.builder().userName("毕翠翠").postName("股衍运营岗").swapHour(0).customerHour(0).foundationHour(0).incomeHour(0).manHour(0).settlementHour(0).manHour(0).build());

//        perfMap.put("肖丹", LedgerZongHeDtoItem.builder().userName("肖丹").postName("综合运营岗").dangWuHour(0).zongHeHour(0).renLiHour(0).xiTongHour(0).ziYouZiJinHour(0).jiaoYiDanYuanHour(0).qiTaHour(0).manHour(0).build());
//        perfMap.put("周洁", LedgerZongHeDtoItem.builder().userName("周洁").postName("综合运营岗").dangWuHour(0).zongHeHour(0).renLiHour(0).xiTongHour(0).ziYouZiJinHour(0).jiaoYiDanYuanHour(0).qiTaHour(0).manHour(0).build());

//        perfMap.put("范漪漪", LedgerJiaoYiDtoItem.builder().userName("范漪漪").postName("综合运营岗").daZongHour(0).ziYouGuZhiHour(0).jiJinHour(0).manHour(0).build());
//        perfMap.put("安恬", LedgerJiaoYiDtoItem.builder().userName("安恬").postName("综合运营岗").daZongHour(0).ziYouGuZhiHour(0).jiJinHour(0).manHour(0).build());
//        perfMap.put("陈诗佳", LedgerJiaoYiDtoItem.builder().userName("陈诗佳").postName("综合运营岗").daZongHour(0).ziYouGuZhiHour(0).jiJinHour(0).manHour(0).build());

//        perfMap.put("安恬", LedgerGuShouDtoItem.builder().userName("安恬").postName("固收运营岗").baoBiaoHour(0).huHuanHour(0).jieSuanHour(0).ziJinHour(0).manHour(0).build());
//        perfMap.put("范漪漪", LedgerGuShouDtoItem.builder().userName("范漪漪").postName("固收运营岗").baoBiaoHour(0).huHuanHour(0).jieSuanHour(0).ziJinHour(0).manHour(0).build());
//        perfMap.put("何泉震", LedgerGuShouDtoItem.builder().userName("何泉震").postName("固收运营岗").baoBiaoHour(0).huHuanHour(0).jieSuanHour(0).ziJinHour(0).manHour(0).build());
//        perfMap.put("姚金岐", LedgerGuShouDtoItem.builder().userName("姚金岐").postName("固收运营岗").baoBiaoHour(0).huHuanHour(0).jieSuanHour(0).ziJinHour(0).manHour(0).build());

        List<PerformanceJiaoYiDto> resultList = Lists.newArrayList();
        PerformanceJiaoYiDto sunwpDto = PerformanceJiaoYiDto.builder().userOaAccount("sunwp").userName("孙伟平").postName("金融业务服务组").build();
        PerformanceJiaoYiDto taoymDto = PerformanceJiaoYiDto.builder().userOaAccount("taoym").userName("陶轶铭").postName("金融业务服务组").build();
        PerformanceJiaoYiDto zzyDto = PerformanceJiaoYiDto.builder().userOaAccount("zzy").userName("赵正彦").postName("金融业务服务组").build();
        PerformanceJiaoYiDto biccDto = PerformanceJiaoYiDto.builder().userOaAccount("bicc").userName("毕翠翠").postName("金融业务服务组").build();

        PerformanceJiaoYiDto xiaodDto = PerformanceJiaoYiDto.builder().userOaAccount("xiaod").userName("肖丹").postName("金融业务服务组").build();
        PerformanceJiaoYiDto zhoujieDto = PerformanceJiaoYiDto.builder().userOaAccount("zhoujie").userName("周洁").postName("金融业务服务组").build();

        PerformanceJiaoYiDto fanyyDto = PerformanceJiaoYiDto.builder().userOaAccount("fanyy").userName("范漪漪").postName("金融业务服务组").build();
        PerformanceJiaoYiDto antDto = PerformanceJiaoYiDto.builder().userOaAccount("ant").userName("安恬").postName("金融业务服务组").build();
        PerformanceJiaoYiDto chenshjDto = PerformanceJiaoYiDto.builder().userOaAccount("chenshj").userName("陈诗佳").postName("金融业务服务组").build();

        PerformanceJiaoYiDto heqzhDto = PerformanceJiaoYiDto.builder().userOaAccount("heqzh").userName("何泉震").postName("金融业务服务组").build();
        PerformanceJiaoYiDto yaojqDto = PerformanceJiaoYiDto.builder().userOaAccount("yaojq").userName("姚金岐").postName("金融业务服务组").build();

        resultList.add(sunwpDto);
        resultList.add(taoymDto);
        resultList.add(zzyDto);
        resultList.add(biccDto);

        resultList.add(xiaodDto);
        resultList.add(zhoujieDto);

        resultList.add(fanyyDto);
        resultList.add(antDto);
        resultList.add(chenshjDto);

        resultList.add(heqzhDto);
        resultList.add(yaojqDto);

        LocalDateTime startTime = obj.getStartTime().atTime(LocalTime.MIDNIGHT);
        LocalDateTime endTime = obj.getEndTime().atTime(LocalTime.MAX);

        sunwpDto.setManHour(dayPerformanceService.findUserSumManHour("sunwp", startTime, endTime));
        taoymDto.setManHour(dayPerformanceService.findUserSumManHour("taoym", startTime, endTime));
        zzyDto.setManHour(dayPerformanceService.findUserSumManHour("zzy", startTime, endTime));
        biccDto.setManHour(dayPerformanceService.findUserSumManHour("bicc", startTime, endTime));
        xiaodDto.setManHour(dayPerformanceService.findUserSumManHour("xiaod", startTime, endTime));
        zhoujieDto.setManHour(dayPerformanceService.findUserSumManHour("zhoujie", startTime, endTime));
        fanyyDto.setManHour(dayPerformanceService.findUserSumManHour("fanyy", startTime, endTime));
        antDto.setManHour(dayPerformanceService.findUserSumManHour("ant", startTime, endTime));
        chenshjDto.setManHour(dayPerformanceService.findUserSumManHour("chenshj", startTime, endTime));
        heqzhDto.setManHour(dayPerformanceService.findUserSumManHour("heqzh", startTime, endTime));
        yaojqDto.setManHour(dayPerformanceService.findUserSumManHour("yaojq", startTime, endTime));

        resultList.forEach(e -> {
            if (Objects.isNull(e.getManHour())) {
                e.setManHour(0);
            }
        });
        resultList = resultList.stream().sorted(Comparator.comparing(PerformanceJiaoYiDto::getManHour).reversed()).collect(Collectors.toList());

        return PlatformResponse.successData(resultList);
    }


}
